package view;
import model.Record;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import java.awt.Color;
import java.awt.Font;
import java.text.NumberFormat;

import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.JFormattedTextField;
import javax.swing.UIManager;


public class RecordView extends JDialog {

	private static final long serialVersionUID = 2342688858850482517L;
	private final JPanel contentPanel = new JPanel();
	private JFormattedTextField inText;
	private JFormattedTextField telstraClearText;
	private JFormattedTextField vodafoneText;
	private JFormattedTextField groceryText;
	private JFormattedTextField internetText;
	private JFormattedTextField electricityText;
	private JFormattedTextField miscText;
	private JLabel totalLabel;
	private JLabel balanceLabel;
	private JFormattedTextField creditCardText;
	private JFormattedTextField nationalBankText;
	private JLabel savedLabel;
	private JLabel totalExpensesLabel;
	private JButton okButton;
	private JButton cancelButton;
	private JTextArea commentTextArea;

	/**
	 * Create the dialog.
	 */
	public RecordView() {
		setAlwaysOnTop(true);
		setTitle("Create Record");
		setResizable(false);
		setModal(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 720, 416);
		setLocationRelativeTo(ParentFrame.getInstance());
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		initComponents();
		inText.setSelectionStart(0);
		inText.setSelectionEnd(25);
	}
	
	public void initComponents() {
		JLabel lblIn = new JLabel("In");
		lblIn.setBounds(15, 23, 10, 14);
		inText = new JFormattedTextField(NumberFormat.getInstance());
		inText.setBorder(UIManager.getBorder("TextField.border"));
		inText.setText("0.00");
		lblIn.setLabelFor(inText);
		inText.setBounds(35, 18, 152, 25);
		inText.setColumns(10);
		contentPanel.setLayout(null);
		contentPanel.add(lblIn);
		contentPanel.add(inText);
		
		JPanel billsPanel = new JPanel();
		billsPanel.setBorder(new TitledBorder(null, "Bills", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		billsPanel.setBounds(15, 54, 255, 286);
		contentPanel.add(billsPanel);
		billsPanel.setLayout(null);
		
		JLabel label = new JLabel("TelstraClear");
		label.setBounds(10, 33, 70, 23);
		billsPanel.add(label);
		
		telstraClearText = new JFormattedTextField(NumberFormat.getInstance());
		telstraClearText.setText("0.00");
		telstraClearText.setColumns(10);
		telstraClearText.setBackground(Color.WHITE);
		telstraClearText.setBounds(90, 32, 155, 25);
		billsPanel.add(telstraClearText);
		
		vodafoneText = new JFormattedTextField(NumberFormat.getInstance());
		vodafoneText.setText("0.00");
		vodafoneText.setColumns(10);
		vodafoneText.setBackground(Color.WHITE);
		vodafoneText.setBounds(90, 67, 155, 25);
		billsPanel.add(vodafoneText);
		
		JLabel label_1 = new JLabel("Vodafone");
		label_1.setBounds(10, 68, 70, 23);
		billsPanel.add(label_1);
		
		groceryText = new JFormattedTextField(NumberFormat.getInstance());
		groceryText.setText("0.00");
		groceryText.setColumns(10);
		groceryText.setBackground(Color.WHITE);
		groceryText.setBounds(90, 103, 155, 25);
		billsPanel.add(groceryText);
		
		JLabel label_2 = new JLabel("Grocery");
		label_2.setBounds(10, 104, 70, 23);
		billsPanel.add(label_2);
		
		internetText = new JFormattedTextField(NumberFormat.getInstance());
		internetText.setText("0.00");
		internetText.setColumns(10);
		internetText.setBackground(Color.WHITE);
		internetText.setBounds(90, 139, 155, 25);
		billsPanel.add(internetText);
		
		JLabel label_3 = new JLabel("Internet");
		label_3.setBounds(10, 140, 70, 23);
		billsPanel.add(label_3);
		
		electricityText = new JFormattedTextField(NumberFormat.getInstance());
		electricityText.setText("0.00");
		electricityText.setColumns(10);
		electricityText.setBackground(Color.WHITE);
		electricityText.setBounds(90, 175, 155, 25);
		billsPanel.add(electricityText);
		
		JLabel label_4 = new JLabel("Electricity");
		label_4.setBounds(10, 176, 70, 23);
		billsPanel.add(label_4);
		
		miscText = new JFormattedTextField(NumberFormat.getInstance());
		miscText.setText("0.00");
		miscText.setColumns(10);
		miscText.setBackground(Color.WHITE);
		miscText.setBounds(90, 211, 155, 25);
		billsPanel.add(miscText);
		
		JLabel label_5 = new JLabel("Misc");
		label_5.setBounds(10, 212, 70, 23);
		billsPanel.add(label_5);
		
		JLabel lblTotal = new JLabel("Total");
		lblTotal.setBounds(10, 246, 46, 14);
		billsPanel.add(lblTotal);
		
		totalLabel = new JLabel("$0.00");
		totalLabel.setFont(new Font("Segoe UI", Font.BOLD, 12));
		totalLabel.setBounds(90, 247, 155, 14);
		billsPanel.add(totalLabel);
		
		JPanel balancePanel = new JPanel();
		balancePanel.setBorder(new TitledBorder(null, "Balance", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		balancePanel.setBounds(279, 11, 416, 43);
		contentPanel.add(balancePanel);
		balancePanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
		
		balanceLabel = new JLabel("$0.00");
		balanceLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
		balancePanel.add(balanceLabel);
		
		JPanel creditCardPanel = new JPanel();
		creditCardPanel.setBorder(new TitledBorder(null, "Credit Card", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		creditCardPanel.setBounds(280, 54, 196, 54);
		contentPanel.add(creditCardPanel);
		creditCardPanel.setLayout(null);
		
		creditCardText = new JFormattedTextField(NumberFormat.getInstance());
		creditCardText.setText("0.00");
		creditCardText.setBounds(18, 20, 166, 25);
		creditCardPanel.add(creditCardText);
		creditCardText.setColumns(20);
		
		JPanel nationalBankPanel = new JPanel();
		nationalBankPanel.setBorder(new TitledBorder(null, "National Bank", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		nationalBankPanel.setLayout(null);
		nationalBankPanel.setBounds(280, 119, 196, 54);
		contentPanel.add(nationalBankPanel);
		
		nationalBankText = new JFormattedTextField(NumberFormat.getInstance());
		nationalBankText.setText("0.00");
		nationalBankText.setColumns(20);
		nationalBankText.setBounds(18, 20, 166, 25);
		nationalBankPanel.add(nationalBankText);
		
		JPanel savedPanel = new JPanel();
		savedPanel.setBorder(new TitledBorder(null, "You Saved", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		savedPanel.setBounds(486, 54, 209, 54);
		contentPanel.add(savedPanel);
		savedPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
		
		savedLabel = new JLabel("$0.00");
		savedLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
		savedPanel.add(savedLabel);
		
		JPanel totalExpensesPanel = new JPanel();
		totalExpensesPanel.setBorder(new TitledBorder(null, "Total Expenses", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		totalExpensesPanel.setBounds(486, 119, 209, 54);
		contentPanel.add(totalExpensesPanel);
		totalExpensesPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0));
		
		totalExpensesLabel = new JLabel("$0.00");
		totalExpensesLabel.setFont(new Font("Segoe UI", Font.BOLD, 16));
		totalExpensesPanel.add(totalExpensesLabel);
		
		JPanel commentPanel = new JPanel();
		commentPanel.setBorder(new TitledBorder(null, "Comment", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		commentPanel.setBounds(280, 184, 416, 156);
		contentPanel.add(commentPanel);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		commentPanel.add(scrollPane);
		
		commentTextArea = new JTextArea();
		commentTextArea.setTabSize(4);
		commentTextArea.setLineWrap(true);
		commentTextArea.setFont(new Font("Segoe UI", Font.PLAIN, 12));
		scrollPane.setViewportView(commentTextArea);
		commentTextArea.setRows(7);
		commentTextArea.setColumns(33);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
	public JFormattedTextField getCreditCardText() {
		return creditCardText;
	}
	public JFormattedTextField getNationalBankText() {
		return nationalBankText;
	}
	public JFormattedTextField getTelstraClearText() {
		return telstraClearText;
	}
	public JButton getOkButton() {
		return okButton;
	}
	public JLabel getBalanceLabel() {
		return balanceLabel;
	}
	public JFormattedTextField getElectricityText() {
		return electricityText;
	}
	public JFormattedTextField getVodafoneText() {
		return vodafoneText;
	}
	public JFormattedTextField getInternetText() {
		return internetText;
	}
	public JLabel getTotalExpensesLabel() {
		return totalExpensesLabel;
	}
	public JFormattedTextField getMiscText() {
		return miscText;
	}
	public JButton getCancelButton() {
		return cancelButton;
	}
	public JFormattedTextField getInText() {
		return inText;
	}
	public JLabel getSavedLabel() {
		return savedLabel;
	}
	public JTextArea getCommentTextArea() {
		return commentTextArea;
	}
	public JLabel getTotalLabel() {
		return totalLabel;
	}
	public JFormattedTextField getGroceryText() {
		return groceryText;
	}
	
	public Record getRecord() {
		Record record = new Record();
		
		record.setComments(getCommentTextArea().getText());
		record.setCreditCard(getCreditCardText().getText());
		record.setElectricity(getElectricityText().getText());
		record.setGrocery(getGroceryText().getText());
		record.setIn(getInText().getText());
		record.setInternet(getInternetText().getText());
		record.setMisc(getMiscText().getText());
		record.setNationalBank(getNationalBankText().getText());
		record.setTelstraClear(getTelstraClearText().getText());
		record.setVodafone(getVodafoneText().getText());
		
		return record;
	}
}
